package com.example.administrator.musicplay;

import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.IBinder;
import android.support.v7.app.NotificationCompat;
import android.widget.Toast;

public class NotificationService extends Service {

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent,int flags,int startId) {
        Toast.makeText(NotificationService.this,"成功启动了Notification",Toast.LENGTH_LONG).show();
        //自定义Notification实例
        NotificationManager notifyManager = (NotificationManager) getSystemService(
                Context.NOTIFICATION_SERVICE);//获取状态通知栏管理
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this);//实例化通知栏构造器
        //以下是对Builder进行配置
        builder.setSmallIcon(R.mipmap.ic_launcher);//设置通知小图标
        builder.setContentTitle("MusicPlay Notification");//通知的标题
        builder.setContentText("5秒钟定时到了");//通知的内容
        notifyManager.notify(1, builder.build());
        return super.onStartCommand(intent, flags, startId);
    }
}
